package org.nullauthor.allthings.gui.screen;

import com.google.common.collect.Lists;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.PageTurnWidget;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.nullauthor.allthings.Allthings;
import org.nullauthor.allthings.gui.handler.EffectUpgradeScreenHandler;
import org.nullauthor.allthings.mods.ModItems;

import java.util.List;

public class EffectUpgradeScreen extends HandledScreen<EffectUpgradeScreenHandler> implements ButtonWidget.PressAction {
    private ButtonWidget buttons;
    public static final Identifier EFFECT_UPGRADE_TEXTURE = new Identifier(Allthings.MOD_ID, "textures/screen/effect_upgrade_screen.png");

    public EffectUpgradeScreen(EffectUpgradeScreenHandler handler, PlayerInventory inventory, Text title) {
        super(handler, inventory, title);
    }

    @Override
    protected void init() {
        super.init();
        int i = (this.width - 176) / 2;
        int j = (this.height - 166) / 2;
        buttons = this.addDrawableChild(ButtonWidget.builder(Text.translatable("effect_upgrade.screen.run"), this).dimensions(i + 73, j + 53, 30, 20).build());

        //buttons = this.addDrawableChild(ButtonWidget.builder(ScreenTexts.DONE, button -> this.close()).dimensions(this.width / 2 - 100, 196, 200, 20).build());
    }

    /**
     * 渲染代码
     *
     * @param context 渲染上下文对象
     * @param mouseX  鼠标X坐标
     * @param mouseY  鼠标Y坐标
     * @param delta   鼠标滚轮偏移量
     */
    @Override
    public void render(DrawContext context, int mouseX, int mouseY, float delta) {
        this.renderBackground(context);
        // 调用父类渲染代码，这个一定要写！
        super.render(context, mouseX, mouseY, delta);
        // 渲染鼠标悬停提示，我们的方块有物品栏的话，没有这行代码，鼠标放在物品上不会有物品提示
        drawMouseoverTooltip(context, mouseX, mouseY);
    }

    @Override
    protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
        RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
        RenderSystem.setShader(GameRenderer::getPositionTexProgram);
        RenderSystem.setShaderTexture(0, EFFECT_UPGRADE_TEXTURE);
        int i = (this.width - 176) / 2;
        int j = (this.height - 166) / 2;
        context.drawTexture(EFFECT_UPGRADE_TEXTURE, i, j, 0, 0, 176, 166);
    }

    @Override
    public void onPress(ButtonWidget button) {
        ItemStack itemStackSlot1 = handler.slots.get(0).getStack();
        ItemStack itemStackSlot2 = handler.slots.get(1).getStack();
        ItemStack itemStackSlot3 = handler.slots.get(2).getStack();
        ItemStack itemStackSlot4 = handler.slots.get(3).getStack();

        itemStackSlot4.addEnchantment(Enchantments.AQUA_AFFINITY, 5);
        itemStackSlot1.decrement(1);
        itemStackSlot2.decrement(1);
        itemStackSlot3.decrement(1);
    }
}
